from player.H5.H5_425new_reglogin import H5_425new_inf_reg
from player.H5.H5_425old_reglogin import H5_425old_inf_reg
from player.H5.H5_LB_reglogin import H5_LB_inf_reg
from player.H5.H5_LBM_reglogin import H5_LBM_inf_reg
from player.unity.Unity_425_reglogin import unity_425_inf_log
from player.unity.Unity_LB_reglogin import unity_LB_inf_log
from Data.Excel import excel
from selenium import webdriver
from Data.suiji import username
import time
import os
import unittest
from HTMLTestRunner import HTMLTestRunner
import pymysql
from mysqlIDB_59 import MysqlDb_59
from mysqlIDB_45 import MysqlDb_45




def Run_425old():
    #执行425old的脚本
    # 获取Excel文档路径
    global H5_425old_ui
    dataList = excel('Data\H5_425old_gameAddr.xlsx')
    for data in dataList:
        H5_425old_ui = H5_425old_inf_reg(data[1], data[2])
        # print(data[2])
        unity_425_inf_log()
    return H5_425old_ui

def Run_425new():
    #执行425newd的脚本
    # 获取Excel文档路径
    global H5_425new_ui
    dataList = excel('Data\H5_425new_gameAddr.xlsx')
    for data in dataList:
        H5_425new_ui = H5_425new_inf_reg(data[1], data[2])
        # print(data[2])
        unity_425_inf_log()
    return H5_425new_ui

def Run_LB():
    #执行萝卜玩官网的脚本
    # 获取Excel文档路径
    global H5_LB_ui
    dataList = excel('Data\H5_LB_gameAddr.xlsx')
    for data in dataList:
        H5_LB_ui = H5_LB_inf_reg(data[1], data[2])
        # print(data[2])
        unity_LB_inf_log()
    return H5_LB_ui

def Run_LBM():
    #执行萝卜玩M站官网的脚本
    # 获取Excel文档路径
    global H5_LBM_ui
    dataList = excel('Data\H5_LBM_gameAddr.xlsx')
    for data in dataList:
        H5_LBM_ui = H5_LBM_inf_reg(data[1], data[2])
        # print(data[2])
        unity_LB_inf_log()
    return H5_LBM_ui

mysqlDB_59 = MysqlDb_59()

def get_realname_status_59():
    realname_status = mysqlDB_59.realname_status()
    return realname_status[0]

mysqlDB_45 = MysqlDb_45()

def get_realname_status_45():
    realname_status = mysqlDB_45.realname_status()
    return realname_status[0]


if __name__ == '__main__':
    #先生成账号名称
    username()
    #print(username())
    #Run_425old()
    #Run_425new()
    Run_LB()
    #username()
    #print(username())
    #Run_LBM()
    # name_59 = get_realname_status_59()
    # print(name_59)
    # if name_59 == 3:
    #     print("数据库验证成功")
    # else:
    #     print("数据库验证失败")

    # name_45 = get_realname_status_45()
    # print(type(name_45))

    db = pymysql.connect(
        host='192.168.28.59',
        port=3306,
        user='fjyl_wujun',
        password='SU2RZvgV3eCS5Bpq',
        charset='utf8',
        database='lbwan_v4_user_db'
    )
    file_username = open(r'unity_username.txt', mode='r')
    sql_name = file_username.read()
    cur = db.cursor()
    cur.execute("SELECT realname_status FROM user_main WHERE user_name = %s", sql_name)
    name = cur.fetchall()
    Real_name = name[0][0]
    print(Real_name)
    if Real_name == 3:
        print("实名认证数据库验证成功")
    else:
        print("实名认证数据库验证失败")

    time.sleep(100)#必须等待100秒，因为游戏的心跳是2分钟之后才会产生并记录在数据表中
    # 连接45数据库
    db = pymysql.connect(
        host='192.168.28.45',
        port=3306,
        user='fjyl_wujun',
        password='SU2RZvgV3eCS5Bpq',
        charset='utf8',
        database='authcenter'
    )
    cur = db.cursor()
    cur.execute("SELECT session_id FROM behavior_login_lbwanh5_251 WHERE session_status = 1;")
    name = cur.fetchall()
    Heat_name1 = name[0][0]
    print(Heat_name1)
    cur.execute("SELECT session_id FROM behavior_online_lbwanh5_251")
    name2 = cur.fetchall()
    Heat_name2 = name2[0][0]
    print(Heat_name2)
    if Heat_name1 == Heat_name2:
        print("心跳数据库验证成功")#如果报IndexError: tuple index out of range错，有可能是心跳未产生导致的
    else:
        print("心跳数据库验证失败")
    print('H5游戏--UI自动化测试结束')

    # print("ceshi")
    # base_dir = os.path.dirname(os.path.realpath(__file__))  # 获取文件当前路径
    # test_dir = os.path.join(base_dir,'TestCases')   # 测试用例所在路径
    # test_report = os.path.join(base_dir, "Reports")  # 测试报告所在路径
    # testlist = unittest.defaultTestLoader.discover(test_dir, pattern='test*.py')
    # now = time.strftime("%Y-%m-%d %H_%M_%S")
    # filename = test_report + "\\" + now + 'result.html'
    # fp = open(filename, 'wb')
    # runner = HTMLTestRunner(stream=fp,
    #                         title=u'接口自动化测试框架设计报告',
    #                         description=u'系统环境：Win10用例执行情况：')
    # runner.run(testlist)
    # fp.close()

